// Domain/Services/RoleManager.cs
using UniversalAdmin.Domain.Repositories;

namespace UniversalAdmin.Domain.Services;

public class RoleManager
{
  private readonly IRoleRepository _roleRepository;

  public RoleManager(IRoleRepository roleRepository)
  {
    _roleRepository = roleRepository;
  }

  public async Task EnsureNameIsUnique(string name, int? excludeRoleId = null)
  {
    if (await _roleRepository.ExistsByNameAsync(name, excludeRoleId))
      throw new InvalidOperationException($"角色名称 '{name}' 已存在");
  }
}